package com.ubao.ui.titlebar;



import android.content.Context;
import android.content.res.Resources;
import android.graphics.Color;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.ubao.R;




public class GTitleBar extends LinearLayout {

	private TextView leftButton;

	private TextView rightButton;
	
	private TextView middleButton;

	
	public GTitleBar(Context context) {
		super(context);
		init(context);
	}

	public GTitleBar(Context context, AttributeSet attrs) {
		super(context, attrs);
		init(context);
	}

	private void init(Context context) {
		Resources resource = getResources();
//		this.setMeasuredDimension(RelativeLayout.LayoutParams.FILL_PARENT,
//				(int) resource.getDimension(R.dimen.titlebar_height));
		this.setGravity(Gravity.CENTER_VERTICAL);
		this.setWeightSum(1);
 
		// Inflate the view from the layout resource.
		String infService = Context.LAYOUT_INFLATER_SERVICE;
		LayoutInflater li = (LayoutInflater) context
				.getSystemService(infService);
		li.inflate(R.layout.widge_titlebar, this);
		InitViews();
	}

	private void InitViews() {
		leftButton = (TextView) findViewById(R.id.leftButton);
		rightButton = (TextView) findViewById(R.id.rightButton);
		middleButton = (TextView) findViewById(R.id.middleButton);
		leftButton.setVisibility(View.GONE);
		rightButton.setVisibility(View.GONE);
		middleButton.setVisibility(View.GONE);
	}
	
	public void initLeftButton(String text,int backgroundresource,OnClickListener listener){
		leftButton.setVisibility(View.VISIBLE);
		leftButton.setText(text);
		leftButton.setBackgroundResource(backgroundresource);
		leftButton.setOnClickListener(listener);
	}
	
	public void initRightButton(String text,int backgroundresource,OnClickListener listener){
		rightButton.setVisibility(View.VISIBLE);
		rightButton.setText(text);
		rightButton.setBackgroundResource(backgroundresource);
		rightButton.setOnClickListener(listener);
	}
	
	public void initTitle(String text){
		middleButton.setVisibility(View.VISIBLE);
		middleButton.setText(text);
	}
	
	public TextView getLeftButton(){
		return leftButton;
	}
	
	public TextView getRightButton(){
		return rightButton;
	}

}
